﻿#region

using System.Linq;
using System.Web.Mvc;
using CuongHanh.Context;
using CuongHanh.Models;

#endregion

namespace CuongHanh.Controllers.FO
{
    public class CartController : BaseController
    {
        public ActionResult CartInfomationOfGem()
        {
            return View();
        }

        public ActionResult CartInfoOfGem(int id,
                int count)
        {
            CartAndPaymentContext.UpdateItemCountOfGem(Session,
                    id,
                    count);
            return PartialView("Partial/_CartInfoOfGem",
                    CartAndPaymentContext.GetBagInfoOfGem(Session));
        }

        public ActionResult RemoveCartItemOfGem(int id)
        {
            CartAndPaymentContext.RemoveCartItemOfGem(Session,
                    id);
            return PartialView("Partial/_CartInfoOfGem",
                    CartAndPaymentContext.GetBagInfoOfGem(Session));
        }

        public ActionResult PaymentOfGem()
        {
            return View(new OrderForGem());
        }

        public ActionResult ServiceFees(bool isDomestic)
        {
            var models = CacheContext<ServiceFee>.Singleton.GetObjectsByFilter(c => c.InVietNam == isDomestic).ToList().Select(c => new
                                                                                                                                    {
                                                                                                                                            Text = string.Format("({0}) {1}",
                                                                                                                                                    c.Code,
                                                                                                                                                    c.Name),
                                                                                                                                            Value = string.Format("{0},{1},{2}",
                                                                                                                                                    c.Id,
                                                                                                                                                    c.ShippingCost,
                                                                                                                                                    c.UtilityFee)
                                                                                                                                    }).ToList();
            string defaultText;
            if(isDomestic)
                defaultText = GetLanguage() == AppUtil.LANGUAGE_EN
                        ? "Select provine"
                        : "Chọn tỉnh thành";
            else
                defaultText = GetLanguage() == AppUtil.LANGUAGE_EN
                        ? "Select Country"
                        : "Chọn quốc gia";

            models.Insert(0,
                    new
                    {
                            Text = defaultText,
                            Value = string.Empty
                    });
            return Json(models);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult AddToCartOfGem(OrderDetailForGem model)
        {
            CartAndPaymentContext.AddToCartOfGem(Session,
                    model);
            return Json("");
        }

        public ActionResult CountCartItemOfGem()
        {
            return PartialView("Partial/_CountCartItemOfGem");
        }
    }
}
